﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using ZLDC.Common.Estate;

namespace ZLDC.Estate.Reports.ReportPages
{
    public partial class UserList_Page : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int typeid = _Request.GetInt("typeid", 0);          // 1盘源更进 2客源跟进 3待看提醒 4已带看 5新添盘源 6新添客源 7独家 8反签 9钥匙 10查看电话 11上传图片盘源 12上传图片数 13自看房源  
                
                string userNoAndName = _Request.GetString("userNoAndName", "");      // 工号及名称

                string userName = string.Empty; // 姓名
                string userNo = string.Empty;   // 工号
                int userId = 0;                 // 楼盘系统用户ID

                if (userNoAndName != "")
                {                    
                    _Utility.GetUserNoAndUserName(userNoAndName, out userName, out userNo);

                    if (_Convert.ToInt(userNo, 0) > 0)
                        userId = _Convert.ToInt(userNo, 0);
                    else
                        userId = ZLDC.Topo.BLL.Estate.UserBLL.GetUserIDByUserNo(userNo);
                }

                int salesmanid = userId;
                if (salesmanid <= 0)
                    salesmanid = _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID, 0);

                string startdate = _Request.GetString("addDate1", DateTime.Today.ToString("yyyy-MM-dd"));
                string enddate = _Request.GetString("addDate2", DateTime.Today.ToString("yyyy-MM-dd"));

                string condition = " where 1=1 ";
                if (salesmanid > 0)
                    condition += " and salesmanid = " + salesmanid.ToString();
                if (startdate != "" && enddate != "")
                    // condition += " and countDate >= '" + startdate + "' and countDate < '" + enddate + "'";
                    condition += " and DATEDIFF(dd, countDate, '" + startdate + "') <= 0 and DATEDIFF(dd, countDate, '" + enddate + "') >= 0";

                DataTable dt = ZLDC.Topo.BLL.Estate.ReportBLL.p_report_dept_list(3, condition);
                                
                //为报表浏览器指定报表文件                
                this.ReportViewer1.LocalReport.ReportPath = Server.MapPath(GetRdlcFilePathByTypeID(typeid));
                
                // 梆定数据集
                this.ReportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource("UserList_Data_t_UserList", dt));

                //显示报表
                this.ReportViewer1.LocalReport.Refresh();
            }
        }

        /// <summary>
        /// 根据类型动态获取rdlc文件路径
        /// </summary>
        /// <param name="typeid"> 1盘源更进 2客源跟进 3待看提醒 4已带看 5新添盘源 6新添客源 7独家 8反签 9钥匙 10查看电话 11上传图片盘源 12上传图片数 13自看房源 </param>
        /// <returns></returns>
        public string GetRdlcFilePathByTypeID(int typeid)
        {
            string rdlcFilePath = "../ReportFiles/UserList_Info_HFollow.rdlc";

            if (typeid == 1)
                rdlcFilePath = "../ReportFiles/UserList_Info_HFollow.rdlc";
            else if (typeid == 2)
                rdlcFilePath = "../ReportFiles/UserList_Info_CFollow.rdlc";
            else if (typeid == 3)
                rdlcFilePath = "../ReportFiles/UserList_Info_Look.rdlc";
            else if (typeid == 4)
                rdlcFilePath = "../ReportFiles/UserList_Info_Looked.rdlc";
            else if (typeid == 5)
                rdlcFilePath = "../ReportFiles/UserList_Info_NewHousing.rdlc";
            else if (typeid == 6)
                rdlcFilePath = "../ReportFiles/UserList_Info_NewCustomer.rdlc";
            else if (typeid == 7)
                rdlcFilePath = "../ReportFiles/UserList_Info_Only.rdlc";
            else if (typeid == 8)
                rdlcFilePath = "../ReportFiles/UserList_Info_Versa.rdlc";
            else if (typeid == 9)
                rdlcFilePath = "../ReportFiles/UserList_Info_Key.rdlc";
            else if (typeid == 10)
                rdlcFilePath = "../ReportFiles/UserList_Info_TelPhone.rdlc";
            else if (typeid == 11)
                rdlcFilePath = "../ReportFiles/UserList_Info_HasPhoto.rdlc";
            else if (typeid == 12)
                rdlcFilePath = "../ReportFiles/UserList_Info_Photo.rdlc";
            else if (typeid == 13)
                rdlcFilePath = "../ReportFiles/UserList_Info_Self.rdlc";
            else if (typeid == 14)
                rdlcFilePath = "../ReportFiles/DeptUserList_Info_NewHousing.rdlc";
            else if (typeid == 15)
                rdlcFilePath = "../ReportFiles/DeptUserList_Info_NewCustomer.rdlc";

            return rdlcFilePath;
        }
    }
}
